package com.xipu.yygh.manage.controller;

import com.xipu.yygh.common.result.R;
import com.xipu.yygh.manage.service.HospManageService;
import com.xipu.yygh.model.hosp.Hospital;
import com.xipu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * description: 医院列表、详情接口
 * @author: gql
 * @date: 2022/05
 */
@RequestMapping("/admin/hosp/hospital")
@RestController
public class HospitalController {
    @Autowired
    private HospManageService hospManageService;

    /**
     * 查询医院列表-带分页
     * @param page 当前页
     * @param limit 每页记录数
     * @param hospitalQueryVo 查询条件
     * @return r
     */
    @GetMapping("findPageHosp/{page}/{limit}")
    public R index(@PathVariable("page") Integer page,
                   @PathVariable("limit") Integer limit,
                   HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> pages = this.hospManageService.selectPage(page, limit, hospitalQueryVo);
        return R.ok().data("pages",pages);
    }

    /**
     * 根据id查询医院详情
     * @param id 医院id
     * @return r
     */
    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") String id) {
        /**
         * 之所以返回Map<String, Object>是因为vue的插值表达式不支持多级取值
         * 而Hospital中包含预约规则BookingRule对象
         */
        Map<String, Object> map = this.hospManageService.show(id);
        return R.ok().data(map);
    }

}
